
package action;

import net.sourceforge.stripes.action.ActionBean;
import net.sourceforge.stripes.action.ActionBeanContext;
import net.sourceforge.stripes.action.DefaultHandler;
import net.sourceforge.stripes.action.ForwardResolution;
import net.sourceforge.stripes.action.Resolution;
import net.sourceforge.stripes.action.UrlBinding;

/**
 * Logout user.
 * @author Tomas CASTA
 */
@UrlBinding("/logout.action")
public class LogoutActionBean implements ActionBean {
    /* action context */
    private ActionBeanContext context;
    
    public ActionBeanContext getContext() {
        return context;
    }

    public void setContext(ActionBeanContext context) {
        this.context = context;
    }

    /**
     * Logout user.
     * @return Resolution
     */
    @DefaultHandler
     public Resolution logout() {
        /* User is logged */
        if (null != context.getRequest().getSession().getAttribute("user")) {

            /* Destroy user session */
            context.getRequest().getSession().invalidate();
        }
        /* User is not logged, cannot logout him, show index */
        return new ForwardResolution("/index.action");
    }

}
